import Vue from 'vue'
import VueRouter from 'vue-router'

import Layout from '@/layout' //布局页


Vue.use(VueRouter)

// 通用页面, 这里的配置不需要权限
export const constRouter = [
    {
        path: '/login',
        component: () => import('@/views/login/Login'),
        hidden: true //导航菜单忽略选项
    },
    {
        path: '',
        component: Layout, //应用布局页
        redirect: '/index',
        hidden: true,
    },
    {
        path: '/index',
        component: Layout, //应用布局页
        name: 'index',
        meta: {
            title: "首页", //导航菜单项标题
            icon: 'el-icon-s-home' //导航菜单图标
        },
        children: [
            {
                path: '',
                component: () => import('@/views/index/index.vue'),
                name: 'indexs',
                meta: {
                    title: "工作台",
                    icon: 'el-icon-s-home',
                    roles: ['admin']
                }
            }
        ]
    },
]

// 动态路由
export const asyncRoutes = [
    {
        path: '/blog',
        component: Layout,
        redirect: '/blog/index',
        meta: {
            title: "博客管理",
            icon: 'el-icon-s-goods',
            hidden: false,
        },
        children: [
            {
                path: 'index',
                component: () => import('@/views/blog/index.vue'),
                name: 'blogList',
                meta: {
                    title: "博客列表",
                    icon: 'el-icon-tickets',
                    hidden: false,
                }
            },
            {
                path: '/blogEdit/:id',
                component: () => import('@/views/blog/edit.vue'),
                name: 'blogEdit',
                meta: {
                    title: "博客列表",
                    icon: 'el-icon-tickets',
                    hidden: true,
                }
            },
            {
                path: 'category',
                component: () => import('@/views/category/index.vue'),
                name: 'categoryList',
                meta: {
                    title: "类别列表",
                    icon: 'el-icon-tickets',
                    hidden: false,
                }
            },
            {
                path: 'label',
                component: () => import('@/views/label/index.vue'),
                name: 'labelList',
                meta: {
                    title: "标签列表",
                    icon: 'el-icon-tickets',
                    hidden: false,
                }
            }
        ]
    },
    {
        path: '/other',
        component: Layout,
        redirect: '/other/imgType',
        meta: {
            title: "其他管理",
            icon: 'el-icon-s-goods',
            hidden: false,
        },
        children: [
            {
                path: 'imgType',
                component: () => import('@/views/image/imgType.vue'),
                name: 'imgType',
                meta: {
                    title: "图片类型列表",
                    icon: 'el-icon-tickets',
                    hidden: false,
                }
            },{
                path: '/other/img/:id',
                component: () => import('@/views/image/index.vue'),
                name: 'img',
                meta: {
                    title: "图片列表",
                    icon: 'el-icon-tickets',
                    hidden: true,
                }
            },
            {
                path: 'link',
                component: () => import('@/views/link/index.vue'),
                name: 'linkList',
                meta: {
                    title: "友链列表",
                    icon: 'el-icon-tickets',
                    hidden: false,
                }
            }
        ]
    }
]

const router = new VueRouter({
    mode: 'hash',
    routes: constRouter
})

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}

export default router

